<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>js面向对象编程</title>
		<script type="text/javascript">
			//无参工厂方法
			function createCar(){
				var oTempCar = new Object;
				oTempCar.color="red";
				oTempCar.doors=4;
				oTempCar.showColor=function(){alert(this.color)}
				return oTempCar;
			}
			var oCar=createCar();
			document.write(oCar.color);
			document.write("<br />");
			oCar.showColor();
			//有参工厂方法
			document.write("<br />");
			function createCar2(sColor,sDoors){
				var oTempCar1 = new Object;
				oTempCar1.color=sColor;
				oTempCar1.doors=sDoors;
				oTempCar1.showCarColor = function(){alert(this.color)};
				return oTempCar1;
			}
			var Car = createCar2("red",4);
			document.write(Car.color);
			//改进的工厂方法
			document.write("<br />");
			function showcolor(){alert(this.color)}
			function createCar2(sColor,sDoors){
				var oTempCar1 = new Object;
				oTempCar1.color=sColor;
				oTempCar1.doors=sDoors;
				oTempCar1.showCarColor = showcolor;
				return oTempCar1;
			}
			var Car1 = createCar2("red",4);
			Car1.showCarColor();
			//原型法
			var day = ["星期一","星期二","星期三","星期四","星期五","星期六","星期日",]
			function showDay(index){
				if (index && index>=1 && index<=7) {
					return day[index-1];
				}
			}
			Date.prototype.showDay=showDay;
			var date = new Date;
			alert(date.showDay(3));
		</script>
	</head>
	<body>
	</body>
</html>
